<template>
	<div class="app-container">
		<div class="app-box">
			<div class="p-detail">
				<p>
					<i class="iconfont icon-baoxianchanpin"></i>
					<span class='set10'>{{info.batchName}}</span>
					<span class="add" v-if='info.isReward'>奖励</span>
					<span class="state state1" v-if='info.state==0'>编辑中</span>
					<span class="state state2" v-else-if='info.state==3'>生效中</span>
					<span class="state state3" v-else-if='info.state==4'>已过期</span>
					<span class="state state4" v-else-if='info.state==1'>待审批</span>
					<span class="state state5" v-else-if='info.state==5'>已驳回</span>
					<span class="state state6" v-else-if='info.state==2'>待生效</span>
				</p>
				<el-dialog title="编辑批次信息"  :close-on-click-modal=false :visible.sync="isshow" width="40%">
					<el-form :model="copyinfo" :rules="rules" ref="copyinfo" label-width="100px" class="demo-ruleForm">
						<el-form-item class="informationaa" label="批次名称:" prop="batchName">
							<el-input v-model="copyinfo.batchName" class="selects" size="mini" placeholder="请输入批次名称"></el-input>
						</el-form-item>

						<el-form-item class="informationaa" label="保险公司:" prop="insuranceId">
							<el-select class="selects" size="mini" disabled v-model="copyinfo.insuranceId" placeholder="请选择保险公司" @change="changecomony(copyinfo.insuranceId)">
								<el-option-group v-for="group in options" :key="group.letter" :label="group.letter">
									<el-option v-for="item in group.insurances" :key="item.id" :label="item.insuranceName" :value="item.id">
									</el-option>
								</el-option-group>
							</el-select>
						</el-form-item>

						<el-form-item class="informationaa" label="适用工号:" prop="staffId">
							<el-select class="selects" size="mini" v-model="copyinfo.staffId" multiple placeholder="请选择">
								<el-option class="selects" v-for="item in workoptions" :key="item.id" :label="item.staffAccount" :value="item.id">
								</el-option>
							</el-select>
						</el-form-item>

						<el-form-item class="informationaa informations" label="有效时间:" required>
							<div class="selects">
								<el-col :span="11">
									<el-form-item prop="effectiveDate">
										<el-date-picker class="dateinp" size="mini" v-model="copyinfo.effectiveDate" :picker-options="startDateOpt" prefix-icon=" " type="datetime" placeholder="生效时间"></el-date-picker>
									</el-form-item>
								</el-col>
								<el-col class="line" :span="2">到</el-col>
								<el-col :span="11">
									<!--endateprop-->
									<el-form-item>
										<el-date-picker class="dateinp" size="mini" v-model="copyinfo.expiryDate" :picker-options="endDateOpt" :disabled="islimit" prefix-icon=" " type="datetime" placeholder="截止时间"></el-date-picker>
									</el-form-item>
								</el-col>
								<div class="sscheckbox">
									<el-checkbox v-model="islimit">不限</el-checkbox>
								</div>
							</div>
						</el-form-item>

						<el-form-item class="informationaa" label=" ">
							<p class="texts">
								<i class="iconfont icon-xuanzhong"></i> 以
								<span>{{copyinfo.matchDateType}}</span>作为匹配日期类型
							</p>
						</el-form-item>
						<el-form-item class="informationaa informationdd">
							<el-button type="primary" size="small" class="btn" :loading="loading1" @click="btn('copyinfo')">确定</el-button>
						</el-form-item>
					</el-form>
				</el-dialog>

				<div class="d-box">
					<div class="editbatch">
						<el-button size="mini" type="info" @click="backs">返回</el-button>
						<el-button size="mini" class="editbatch_edit" @click="batchedit" v-if="info.state==0||info.state==5">编辑批次信息</el-button>
					</div>
					<p>
						<span>保险公司：</span>
						<span class="d-setc">{{info.insuranceName}}</span>
						<span class="set30">有效日期：</span>
						<span class="d-setc">{{info.effectiveDate}} 到 &nbsp;</span>
						<span class="d-setc" v-if="info.expiryDate">{{info.expiryDate}}&nbsp;&nbsp;</span>
						<span class="d-setc" v-else>不限</span>

						<span class="set30">匹配日期类型：</span>
						<span class="d-setc">{{info.matchDateType}}</span>&nbsp;&nbsp;
					</p>
					<div class="minflao">
						<span class="minflao_first">适用工号：</span>
						<span class="d-setc" v-for='(item,index) in info.staffNames'>
							<span class="isF">&nbsp;&nbsp;|&nbsp;&nbsp;</span>{{item.staffAccount}}（{{item.describe}}）
							<span v-if="info.staffNames.length-1!=index">，</span>
						</span>
						<div style="clear:both"></div>
					</div>
				</div>
			</div>
			<div class="p-list">
				<!-- <table class="util-table">
					<tr>
						<th rowspan="2" width="655">政策备注信息</th>
						<th colspan="2" width="149" style="border:1px solid white;border-top:0;">交强险</th>
						<th colspan="2" width="149" style="border:1px solid white;border-top:0;">商业险</th>
						<th rowspan="2" width="132">操作</th>
					</tr>
					<tr class="havebor">
						<th width="100">佣金</th>
						<th width="100" style="border-right:1px solid white">奖励</th>
						<th width="100">佣金</th>
						<th width="100">奖励</th>
					</tr>
					
					
				</table> -->
				<table width="100%" class="table-top" border="0" style="margin-top:30px;">
					<tr>
						<th width="41%" colspan="6">政策备注信息</th>
						<th colspan="6" width="59%">
							<table width="100%" border="0" class="table-two">
								<tr>
									<th colspan="2" width="34%" style="border-left:0;border-right:0;border-top:0;border-bottom:1px solid #fff">交强险</th>
									<th colspan="2" width="34%" style="border-width: 0px 1px 1px; border-top-style: initial; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: initial; border-right-color: white; border-bottom-color: white; border-left-color: white; border-image: initial;">商业险</th>
									<th rowspan="2" width="16%">操作</th>
								</tr>
								<tr>

									<th width="17%">佣金</th>
									<th width="17%" style="border-right: 1px solid white;">奖励</th>
									<th width="17%">佣金</th>
									<th width="17%">奖励</th>
								</tr>
							</table>
						</th>

					</tr>
				</table>
				<div id="ps"  class="minheight" style="min-height:300px" v-loading="loadding">
				</div>
			</div>
			<div class="p-btn">
				<!--<el-button size='mini' class='wd100 setborder' @click='toUp()'>上一步</el-button>
				<el-button size='mini' type='primary' class='wd100' @click='toNext()'>下一步</el-button>-->
				<el-button size='mini' v-if="info.state==0||info.state==5" :disabled="rovalDisa" class='wd100 setborder' @click="toexamine" :loading="loading2">{{rovalHtml}}</el-button>
				<el-button size='mini' v-if="info.state==0||info.state==5" class='wd100 setborder' @click="deletebatch" :loading="loading4">删除</el-button>
				<el-button size='mini' v-if="info.state==1&&this.Jurisdiction==1" class='wd100 setborder' @click="Applicationeditor" :loading="loading3">申请编辑</el-button>
				<el-button size='small' v-if="info.state==2||info.state==3||info.state==4" class='setborder' @click="generate">生成下游政策</el-button>
				<el-button size='mini' v-if="info.state==1&&this.Jurisdiction==2" class='wd100 setborder' @click="adopt" :loading="loading5">通过</el-button>
				<el-button size='mini' v-if="info.state==1&&this.Jurisdiction==2" class='wd100 setborder' @click="reject" :loading="loading6">驳回</el-button>
			</div>
		</div>
		<el-dialog title="审核提示" :visible.sync="dialogTableVisible" width="500px" class="toDis-dialog upper4-dialog" :close-on-click-modal="false">
			<p class="dialog-tit">
				当前批次（{{info.batchName}}）与以下政策批次有效时间重叠，点击“确定”，系统将在当前批次（{{info.batchName}}）审核通过后自动修改重叠批次的截止时间为当前批次的开始时间 {{info.effectiveDate}}
			</p>
			<div class="dialog-max">
				<div class="visi-wrp" v-for="(item,index) in existence">
					<!--<div class="visi-wrp">-->
					<div class="visi-list">
						<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;批次名称：{{item.batchName}}</div>
						<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;有效时间：{{item.effectiveDate}} 到
							<span v-if="item.expiryDate">{{item.expiryDate}}</span>
							<span v-else>不限</span>
						</div>
					</div>
				</div>
			</div>
			<div slot="footer" class="dialog-footer">
				<el-button class="upper4-sureBtn" @click="goEdit">取消</el-button>
				<el-button class="upper4-sureBtn" type="primary" @click="toRoval_sure()">确 定</el-button>
			</div>
		</el-dialog>

		<el-dialog title="审核提示" :visible.sync="ex_dialogTableVisible" width="500px" class="toDis-dialog upper4-dialog" :close-on-click-modal="false">
			<p class="dialog-tit">
				当前批次（{{info.batchName}}）与以下政策批次有效时间重叠，审核通过后,系统会自动将当前批次（{{info.batchName}}）的开始时间修改为重叠批次的截止时间 {{info.effectiveDate}}
			</p>
			<div class="dialog-max">
				<div class="visi-wrp" v-for="(item,index) in existence">
					<!--<div class="visi-wrp">-->
					<div class="visi-list">
						<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;批次名称：{{item.batchName}}</div>
						<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;有效时间：{{item.effectiveDate}} 到
							<span v-if="item.expiryDate">{{item.expiryDate}}</span>
							<span v-else>不限</span>
						</div>
					</div>
				</div>
			</div>
			<div slot="footer" class="dialog-footer">
				<el-button class="upper4-sureBtn" @click="ex_goEdit">取消</el-button>
				<el-button class="upper4-sureBtn" type="primary" @click="ex_toRoval_sure()">确 定</el-button>
			</div>
		</el-dialog>

		<el-dialog title="驳回原因" :visible.sync="Rejectshow" width="690px" class="toDis-dialog2" :close-on-click-modal="false">
			<el-form :model="ruleForm" :rules="rule" ref="ruleForm" label-width="100px" class="demo-ruleForm">
				<el-row :gutter="20">
					<el-form-item label="" prop="dismissalSeason">
						<el-input class="toDis-textarea" type="textarea" rows="12" placeholder="请输入驳回原因" v-model="ruleForm.dismissalSeason"></el-input>
					</el-form-item>
				</el-row>
				<el-form-item class="dialog-sec-wp">
					<div class="btncenters">
						<el-button size="small" type="primary" class="toDis-toRoval-btn btncenter" @click="toDis_sure('ruleForm')">确 定</el-button>
					</div>

				</el-form-item>
			</el-form>
		</el-dialog>
	</div>
</template>
<script>
import Vue from "vue";
import nextnav from "./assembly/nextnav";

import system from "@/components/system";
export default {
  data() {
    return {
      isdelete: false,
      indexs: null,
      indexs_tow: null,
      id: "", //当前id
      policylist: [],
      info: {},
      copyinfo: {
        staffId: []
      },
      navnum: 2,
      insuranceId: "",
      isshow: false,
      rules: {
        batchName: [
          {
            required: true,
            message: "请输入批次名称",
            trigger: "blur"
          }
        ],
        insuranceId: [
          {
            required: true,
            message: "请选择保险公司",
            trigger: "change"
          }
        ],
        staffId: [
          {
            required: true,
            message: "请选择适用工号",
            trigger: "change"
          }
        ]
      },

      workoptions: [],
      options: [],
      policyBatchType: 0, //上游  批次类型
      existence: [],
      rovalHtml: "提交审核",
      rovalDisa: false,
      dialogTableVisible: false,
      ex_dialogTableVisible: false,
      Rejectshow: false,
      ruleForm: {
        dismissalSeason: null
      },
      rule: {
        dismissalSeason: [
          { required: true, message: "请输入驳回原因", trigger: "blur" }
        ]
      },
      islimit: false,
      endDateOpt: this.enddate(),
      startDateOpt: this.startdate(),
      additional: {},
      status: "",
      Jurisdiction: "",
      loading1:false,
      loading2:false,
      loading3:false,
      loading4:false,
      loading5:false,
      loading6:false,
      loadding:false,
    };
  },
  mounted() {
    this.Jurisdiction = this.$route.query.Jurisdiction;
    this.id = this.$route.query.batchId;

    this.getBasic();
    console.log(this.Jurisdiction);
    console.log(this.info.state);
    this.getPolicyList();
    if (this.$route.query.batchId) {
      this.id = this.$route.query.batchId;
      this.getSys();
    }
  },
  components: {
    nextnav
  },
  methods: {
    //系统模板
    getSys() {
      const me = this;
      new system({
        batchid: this.$route.query.batchId,
        source:this.$route.name,
        status:this.status,
         created:function(){
           me.loadding = true
        },
        success: function(vm) {
           me.loadding = false
         // vm.$nextTick(function() {
            // DOM 现在更新了
            // `this` 绑定到当前实例
          //  me.$forceUpdate();
            // me.getSelf()
//});
          // vm.$destroy()
          // vm.$forceUpdate()
          // me.getSelf()
        }
      });
    },
    getSelf() {
      const me = this;
      me.$forceUpdate();
      this.getSys();
    },
    //返回
    backs() {
      this.$router.go(-1);
    },
    //验证输入
    blurs1(val) {
      console.log(this.additional);
      if (this.additional.brokerageBusinessType == 0) {
        let aa = this.clearNoNum(val.target.value);
        Vue.set(this.additional, "upperBrokerageTraffic", aa);
      } else {
        let aa = this.clearNoNums(val.target.value);
        Vue.set(this.additional, "upperBrokerageTraffic", aa);
      }
    },
    blurs2(val) {
      if (this.additional.brokerageBusinessType == 0) {
        let aa = this.clearNoNum(val.target.value);
        Vue.set(this.additional, "upperRewardTraffic", aa);
      } else {
        let aa = this.clearNoNums(val.target.value);
        Vue.set(this.additional, "upperRewardTraffic", aa);
      }
    },
    blurs3(val) {
      if (this.additional.brokerageBusinessType == 0) {
        let aa = this.clearNoNum(val.target.value);
        Vue.set(this.additional, "upperBrokerageBusiness", aa);
      } else {
        let aa = this.clearNoNums(val.target.value);
        Vue.set(this.additional, "upperBrokerageBusiness", aa);
      }
    },
    blurs4(val) {
      if (this.additional.brokerageBusinessType == 0) {
        let aa = this.clearNoNum(val.target.value);
        Vue.set(this.additional, "upperRewardBusiness", aa);
      } else {
        let aa = this.clearNoNums(val.target.value);
        Vue.set(this.additional, "upperRewardBusiness", aa);
      }
    },
    clearNoNum(obj) {
      obj = obj.replace(/[^\d.]/g, ""); //清除“数字”和“.”以外的字符
      obj = obj.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的
      obj = obj
        .replace(".", "$#$")
        .replace(/\./g, "")
        .replace("$#$", ".");
      obj = obj.replace(/^(\-)*(\d+)\.(\d\d).*$/, "$1$2.$3"); //只能输入两个小数
      if (obj.indexOf(".") < 0 && obj != "") {
        //以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
        obj = parseFloat(obj);
      }
      if (obj >= 100) {
        obj = 100;
      }
      if (obj == "") {
        obj = 0;
      }
      console.log(obj);
      return obj;
    },
    clearNoNums(obj) {
      obj = obj.replace(/[^\d.]/g, ""); //清除“数字”和“.”以外的字符
      obj = obj.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的
      obj = obj
        .replace(".", "$#$")
        .replace(/\./g, "")
        .replace("$#$", ".");
      obj = obj.replace(/^(\-)*(\d+)\.(\d\d).*$/, "$1$2.$3"); //只能输入两个小数
      if (obj.indexOf(".") < 0 && obj != "") {
        //以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
        obj = parseFloat(obj);
      }
      if (obj == "") {
        obj = 0;
      }
      console.log(obj);
      return obj;
    },
    //编辑基本嘻嘻
    btn(formName) {
      console.log(this.copyinfo);
      this.copyinfo.id = this.id;
      this.$refs[formName].validate(valid => {
        if (valid) {
        	this.loading1=true
          let params = this.copyinfo;
          this.post(params, "services/app/policy/CreateUpperPolicyBatch").then(
            res => {
              if (res.success) {
              	this.loading1=false
                console.log(res);
                this.getBasic();
                this.isshow = false;
              } else {
              	this.loading1=false
                this.$notify.error({
                  title: "错误",
                  message: res.error.message
                });
              }
            }
          );
        } else {
          console.log(235);
          return false;
        }
      });
    },
    //开始时间
    startdate() {
      var that = this;
      return {
        disabledDate(time) {
          if (that.copyinfo.expiryDate) {
            return time.getTime() > that.copyinfo.expiryDate;
          } else {
            return that.copyinfo.expiryDate;
          }
        }
      };
    },
    //结束时间
    enddate() {
      var that = this;
      return {
        disabledDate(time) {
          return time.getTime() < that.copyinfo.effectiveDate;
        }
      };
    },
    //去修改
    goEdit() {
      this.dialogTableVisible = false;
    },
    ex_goEdit() {
      this.ex_dialogTableVisible = false;
    },
    //继续提交
    toRoval_sure() {
      this.dialogTableVisible = false;
      this.toRovalPost();
      //this.Updatestate()
    },
    ex_toRoval_sure() {
      this.ex_dialogTableVisible = false;
      this.adpass();
      this.Updatestate();
    },
    //更新状态
    Updatestate(val) {
      let str = "";
      for (let i = 0; i < this.existence.length; i++) {
        if (i == this.existence.length - 1) {
          str += this.existence[i].policyBatchId;
        } else {
          str += this.existence[i].policyBatchId + ",";
        }
      }
      let params = {
        policyBatchId: this.id
      };

      this.post(params, "services/app/policy/UpdateExpiryDate").then(re => {
        if (re.success) {
          console.log(re);
        } else {
          this.failNot(re.error.message);
        }
      });
    },
    //申请编辑
    Applicationeditor() {
      //policyBatchId
      let params = {
        policyBatchId: this.id
      };
      var txt = "确定申请编辑吗？";
      this.$confirm(txt, "审核提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        closeOnClickModal: false
        // type: 'warning'
      }).then(() => {
      	this.loading3=true
        this.post(
          params,
          "services/app/policy/UpdatePolicyBatchStateToEditing"
        ).then(re => {
          if (re.success) {
          	this.loading3=false
            console.log(re);
            this.$notify({
              title: "提交成功",
              message: "您已成功申请编辑",
              type: "success",
              customClass: "el-notification-success"
            });
            this.$router.push({
              name: "policyup"
            });
          } else {
          	this.loading3=false
            this.failNot(re.error.message);
          }
        });
      });
    },
    //删除批次
    deletebatch() {
      let params = {
        id: this.id
      };
      var txt = "确定删除吗？";
      this.$confirm(txt, "审核提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        closeOnClickModal: false
        // type: 'warning'
      }).then(() => {
      	this.loading4=true
        this.post(params, "services/app/policy/DeletePolicyBatch").then(re => {
          if (re.success) {
          	this.loading4=false
            console.log(re);
            this.$notify({
              title: "删除成功",
              message: "您已成功删除一条上游批次",
              type: "success",
              customClass: "el-notification-success"
            });
            this.$router.push({
              name: "policyup"
            });
          } else {
          	this.loading4=false
            this.failNot(re.error.message);
          }
        });
      });
    },
    //通过
    adopt() {
      if (this.existence.length == 0) {
        //无冲突
        var txt = "确定通过审核吗？";
        this.$confirm(txt, "审核提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          closeOnClickModal: false
          // type: 'warning'
        }).then(() => {
          this.adpass();
        });
      } else {
        //有冲突
        this.ex_dialogTableVisible = true;
      }
    },
    //通过2
    adpass() {
    	this.loading5=true
      let params = {
        policyBatchId: this.id
      };
      this.post(
        params,
        "services/app/policy/UpdatePolicyBatchStateToApproval"
      ).then(re => {
        if (re.success) {
        	this.loading5=false
          console.log(re);
          this.successNot();
          this.$router.push({
            name: "policyup"
          });
        } else {
        	this.loading5=false
          this.failNot(re.error.message);
        }
      });
    },
    //驳回
    reject() {
      this.Rejectshow = true;
      Vue.set(this.ruleForm, "dismissalSeason", "");
    },
    //生成下游政策
    generate() {
      let params = {
        id: this.id
      };
      var txt = "确定生成下游政策吗？";
      this.$confirm(txt, "审核提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        closeOnClickModal: false
        // type: 'warning'
      }).then(() => {
        this.post(
          params,
          "services/app/policy/CreatePolicyBatchFormUpper"
        ).then(re => {
          if (re.success) {
            console.log(re);

            this.$router.push({
              name: "policydownnew",
              query: {
                id: this.id
              }
            });
          } else {
            this.failNot(re.error.message);
          }
        });
      });
    },
    toDis_sure(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
        	this.loading6=true
          let params = {
            policyBatchId: this.id,
            dismissalSeason: this.ruleForm.dismissalSeason
          };
          this.post(
            params,
            "services/app/policy/UpdatePolicyBatchStateToDismissal"
          ).then(res => {
            if (res.success) {
            this.loading6=false

              this.$router.push({
                name: "policyup"
              });
              this.Rejectshow = false;
            }else{
            	this.loading6=false
            	 this.failNot(re.error.message);
            }
          });
        } else {
         
        }
      });
    },
    //提交审核
    toexamine() {
      if (this.existence.length == 0) {
        //无冲突
        var txt = "确定提交审核吗？";
        this.$confirm(txt, "审核提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          closeOnClickModal: false
          // type: 'warning'
        }).then(() => {
          this.toRovalPost();
        });
      } else {
        //有冲突
        this.dialogTableVisible = true;
      }
    },
    //无冲突提交
    toRovalPost() {
      let params = {
        policyBatchId: this.id
      };
      this.loading2=true
      this.post(
        params,
        "services/app/policy/UpdatePolicyBatchStateToApprovalPending"
      ).then(re => {
        if (re.success) {
        	  this.loading2=false
          this.rovalHtml = "已提交";
          this.rovalDisa = true;
          this.$notify({
            title: "提交成功",
            message: "您已成功提交审核",
            type: "success",
            customClass: "el-notification-success"
          });
          this.$router.push({
            name: "policyup"
          });
        } else {
        	this.loading2=false
          this.failNot(re.error.message);
        }
      });
    },
    //保存成功提示
    successNot() {
      this.$notify({
        title: "提交成功",
        message: "您已成功提交一条上游批次",
        type: "success",
        customClass: "el-notification-success"
      });
    },
    //保存失败提示
    failNot(message) {
      this.$notify.error({
        title: "保存失败",
        message: message,
        duration: 0,
        customClass: "el-notification-error"
      });
    },
    //更改公司
    changecomony(val) {
      //this.copyinfo.staffId=[]
      console.log("success");
      console.log(val);
      //this.info.insuranceId=val
      Vue.set(this.copyinfo, "insuranceId", val);
      let arr = [];
      Vue.set(this.copyinfo, "staffId", arr);
      console.log(this.copyinfo.staffId);
      this.getWorknumber();
    },
    //获取工号
    getWorknumber() {
      console.log(this.copyinfo.staffId);
      let params = {
        id: this.copyinfo.insuranceId
      };
      //Vue.set(this.copyinfo,"staffId",[])
      this.post(params, "services/app/common/GetCurrentInsuranceStaffs").then(
        res => {
          var arr = [];
          //this.workoptions
          arr = res.result.items;
          for (var i = 0; i < arr.length; i++) {
            if (arr[i].describe != "") {
              arr[i].staffAccount =
                arr[i].staffAccount + " (" + arr[i].describe + ")";
            } else {
              arr[i].staffAccount = arr[i].staffAccount;
            }
          }
          this.workoptions = arr;
          console.log("num");
          console.log(arr);
        }
      );
    },
    //获取公司列表
    getcommoy() {
      let params = {};
      this.post(params, "services/app/common/GetGroupInsurances").then(res => {
        this.options = res.result.items;
      });
    },
    //编辑批次信息
    batchedit() {
      let str = JSON.stringify(this.info);
      this.copyinfo = JSON.parse(str);
      let arr = [];
      console.log(this.copyinfo.staffNames);
      for (let i = 0; i < this.copyinfo.staffNames.length; i++) {
        arr.push(this.copyinfo.staffNames[i].staffId);
      }
      Vue.set(this.copyinfo, "staffId", arr);
      console.log(this.copyinfo);
      this.isshow = true;
    },
    //信息
    getBasic() {
      let params = {
        id: this.id
      };
      this.post(params, "services/app/policy/GetPolicyBatchBasic").then(rs => {
        if (rs.success) {
          console.log("successsss");
          console.log(rs);
          this.info = rs.result;
          let str = JSON.stringify(this.info);
          this.copyinfo = JSON.parse(str);
          this.status = rs.result.state;
          this.insuranceId = rs.result.insuranceId;
          if (this.info.expiryDate) {
            //islimit
            console.log(11);
            this.islimit = false;
          } else {
            console.log(22);
            this.islimit = true;
          }

          this.getcommoy();
          this.getWorknumber();
        } else {
          this.$notify.error({
            title: "错误",
            message: res.error.message
          });
        }
      });
      this.post(params, "services/app/policy/CheckEffectivedPolicyBatch").then(
        res => {
          if (res.success) {
            this.existence = res.result.items;
            console.log("existence");
            console.log(this.existence);
          } else {
            this.$notify.error({
              title: "错误",
              message: res.error.message
            });
          }
        }
      );
    },
    //编辑展示
    editshow(val, e) {
      this.isdeletefalse();
      let str = JSON.stringify(val);
      this.additional = JSON.parse(str);
      var arr = [];
      for (let i = 0; i < this.policylist.length; i++) {
        arr.push(this.policylist[i]);
        if (e == i) {
          arr[i].iseditshow = true;
        } else {
          arr[i].iseditshow = false;
        }
      }
      this.policylist = arr;
    },
    //取消编辑
    edithide() {
      var arr = [];
      for (let i = 0; i < this.policylist.length; i++) {
        arr.push(this.policylist[i]);
        arr[i].iseditshow = false;
      }
      this.policylist = arr;
    },
    isdeletetrue(val, e) {
      this.edithide();
      console.log(1111);
      var arr = [];
      for (let i = 0; i < this.policylist.length; i++) {
        arr.push(this.policylist[i]);
        if (e == i) {
          arr[i].isdelete = true;
        } else {
          arr[i].isdelete = false;
        }
      }
      this.policylist = arr;
      console.log(this.policylist);
    },
    isdeletefalse() {
      var arr = [];
      for (let i = 0; i < this.policylist.length; i++) {
        arr.push(this.policylist[i]);
        arr[i].isdelete = false;
      }
      this.policylist = arr;
    },
    //修改单挑政策数据
    subpolicy() {
      let a1 = parseFloat(this.additional.upperBrokerageBusiness);
      let a2 = parseFloat(this.additional.upperRewardBusiness);
      let b1 = parseFloat(this.additional.upperBrokerageTraffic);
      let b2 = parseFloat(this.additional.upperRewardTraffic);
      console.log(a1);
      console.log(a2);
      console.log(b1);
      console.log(b2);
      let obj = {
        policyId: this.additional.policyId,
        upperBrokerageBusiness: this.additional.upperBrokerageBusiness,
        upperRewardBusiness: this.additional.upperRewardBusiness,
        upperBrokerageTraffic: this.additional.upperBrokerageTraffic,
        upperRewardTraffic: this.additional.upperRewardTraffic,
        upperBrokerageVehicleTax: "",
        upperRewardVehicleTax: ""
      };
      if (this.additional.brokerageBusinessType == 0) {
        if (a1 + a2 > 100 && b1 + b2 > 100) {
          this.indexs_tow = 2;
          this.indexs = 1;
        } else if (a1 + a2 > 100 || b1 + b2 > 100) {
          if (a1 + a2 > 100) {
            this.indexs_tow = 2;
            this.indexs = null;
          } else {
            this.indexs_tow = null;
            this.indexs = 1;
          }
        } else {
          this.indexs_tow = null;
          this.indexs = null;
          let arr = [];
          arr.push(obj);
          let params = {
            items: arr
          };

          this.post(params, "services/app/policy/UpdateUpperPolicyCustom").then(
            rs => {
              if (rs.success) {
                console.log("success");
                console.log(rs);
                this.getPolicyList();
                this.edithide();
              } else {
                this.$notify.error({
                  title: "错误",
                  message: res.error.message
                });
              }
            }
          );
        }
      } else {
        this.indexs_tow = null;
        this.indexs = null;
        let arr = [];
        arr.push(obj);
        let params = {
          items: arr
        };

        this.post(params, "services/app/policy/UpdateUpperPolicyCustom").then(
          rs => {
            if (rs.success) {
              console.log("success");
              console.log(rs);
              this.getPolicyList();
              this.edithide();
            } else {
              this.$notify.error({
                title: "错误",
                message: res.error.message
              });
            }
          }
        );
      }
    },
    //删除政策
    deletepolicy(val) {
      let params = {
        policyBatchType: 0,
        policyId: val
      };
      this.post(params, "services/app/policy/DeletePolicy").then(res => {
        console.log(res);
        if (res.success) {
          this.$notify({
            title: "删除成功",
            message: "您已成功删除一条政策",
            type: "success",
            customClass: "el-notification-success"
          });
          this.getPolicyList();
        } else {
          this.$notify.error({
            title: "错误",
            message: res.error.message
          });
        }
      });
    },
    //信息表
    getPolicyList() {
      let params = {
        id: this.id
      };
      this.post(params, "services/app/policy/GetPolicyList").then(rs => {
        if (rs.success) {
          console.log("shuju");
          console.log(rs.result.items);
          let arr = ([] = rs.result.items);
          let re = /^[0-9]+.?[0-9]*/;
          arr.forEach(item => {
            if (item) {
              item.iseditshow = false;
              item.isdelete = false;
              for (var i in item) {
                if (re.test(item[i])) {
                  //										if(item[i] == 0){
                  //											item[i] = '';
                  //										}
                }
                //									if(i == 'upperBrokerageTraffic' && item['upperBrokerageTraffic'] == ''){
                //										item['upperBrokerageTraffic'] = '4';
                //									}
                //									if(i == 'upperBrokerageTraffic'){
                //										item[i] = item[i]+'';
                //									}
                //									if(i == 'upperRewardTraffic'){
                //										item[i] = item[i]+'';
                //									}
                //									if(i == 'upperBrokerageBusiness'){
                //										item[i] = item[i]+'';
                //									}
                //									if(i == 'upperRewardBusiness'){
                //										item[i] = item[i]+'';
                //									}
              }
            }
          });
          this.policylist = arr;
          console.log("shuju2");
          console.log(this.policylist);
        }
      });
    },
    //两位小数
    twoBit(value) {
      if (value) {
        console.log(value);
        value = value.replace(/[^\d.]/g, ""); //清除“数字”和“.”以外的字符
        value = value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的
        value = value
          .replace(".", "$#$")
          .replace(/\./g, "")
          .replace("$#$", ".");
        value = value.replace(/^(\-)*(\d+)\.(\d\d).*$/, "$1$2.$3"); //只能输入两个小数
        if (value.indexOf(".") < 0 && value != "") {
          //以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
          value = parseFloat(value);
        }
        // value = value;
        return value;
      }
    },
    //验证小数
    getTest(item) {
      // console.log(item);
      const that = this;
      // let re = /^[0-9\.]+$/g;
      let re2 = /^\d+(\.\d{1,2})?$/;
      for (let i in item) {
        if (
          i == "upperBrokerageTraffic" ||
          i == "upperRewardTraffic" ||
          i == "upperBrokerageBusiness" ||
          i == "upperRewardBusiness"
        ) {
          if (!re2.test(item[i])) {
            Vue.set(item, i, that.twoBit(item[i]));
            this.getchange(item);
            // console.warn(item[i]);
          }
        }
      }
    },
    //验证100
    getchange(item) {
      // console.log(item);
      const that = this;
      let re = /^[0-9]+.?[0-9]*/;
      for (var i in item) {
        if (item[i] === "") {
          item[i] = "0";
        }
        if (re.test(item[i])) {
          if (i == "upperBrokerageTraffic") {
            if (Number(item[i]) + Number(item["upperRewardTraffic"]) > 100) {
              Vue.set(item, "traffic", true);
            } else {
              Vue.set(item, "traffic", false);
            }
            if (Number(item[i]) > 100) {
              Vue.set(item, "traffic1", true);
            } else {
              Vue.set(item, "traffic1", false);
            }
          }
          if (i == "upperRewardTraffic") {
            if (Number(item[i]) + Number(item["upperBrokerageTraffic"]) > 100) {
              Vue.set(item, "traffic", true);
            } else {
              Vue.set(item, "traffic", false);
            }
            if (Number(item[i]) > 100) {
              Vue.set(item, "traffic2", true);
            } else {
              Vue.set(item, "traffic2", false);
            }
          }
          if (i == "upperBrokerageBusiness") {
            if (Number(item[i]) + Number(item["upperRewardBusiness"]) > 100) {
              Vue.set(item, "business", true);
            } else {
              Vue.set(item, "business", false);
            }
            if (Number(item[i]) > 100) {
              Vue.set(item, "business1", true);
            } else {
              Vue.set(item, "business1", false);
            }
          }
          if (i == "upperRewardBusiness") {
            if (
              Number(item[i]) + Number(item["upperBrokerageBusiness"]) >
              100
            ) {
              Vue.set(item, "business", true);
            } else {
              Vue.set(item, "business", false);
            }
            if (Number(item[i]) > 100) {
              Vue.set(item, "business2", true);
            } else {
              Vue.set(item, "business2", false);
            }
          }
          /*if(i == 'upperBrokerageVehicleTax'){
							if(Number(item[i])+Number(item['upperRewardVehicleTax']) > 100){
								Vue.set(item,'vehicle',true)
							}else{
								Vue.set(item,'vehicle',false)
							}
							if(Number(item[i])>100){
								Vue.set(item,'vehicle1',true)
							}else{
								Vue.set(item,'vehicle1',false)
							}
						}
						if(i == 'upperRewardVehicleTax'){
							if(Number(item[i])+Number(item['upperBrokerageVehicleTax']) > 100){
								Vue.set(item,'vehicle',true)
							}else{
								Vue.set(item,'vehicle',false)
							}
							if(Number(item[i])>100){
								Vue.set(item,'vehicle2',true)
							}else{
								Vue.set(item,'vehicle2',false)
							}
						}*/
        }
      }
    },
    //遍历，空为0
    eachArr2(arr) {
      let re = /^[0-9]+.?[0-9]*/;
      arr.forEach(item => {
        if (item) {
          for (var i in item) {
            if (re.test(item[i])) {
              if (item[i] == "") {
                item[i] = "0";
              }
            }
            if (
              i == "upperBrokerageTraffic" &&
              item["upperBrokerageTraffic"] == ""
            ) {
              item[i] = "0";
              console.log(item[i]);
            }
            if (i == "upperRewardTraffic" && item["upperRewardTraffic"] == "") {
              item[i] = "0";
            }
            if (
              i == "upperBrokerageBusiness" &&
              item["upperBrokerageBusiness"] == ""
            ) {
              item[i] = "0";
            }
            if (
              i == "upperRewardBusiness" &&
              item["upperRewardBusiness"] == ""
            ) {
              item[i] = "0";
            }
          }
        }
      });
      return arr;
    },
    //下一步
    toNext() {
      console.log(this.policylist);
      if (this.policylist.length == 0) {
        this.$message({
          type: "warning",
          message: "请新建政策"
        });
      } else {
        let obj = [];
        const that = this;
        obj = this.policylist.map(e => {
          //实现深拷贝
          if (typeof e === "object") {
            return Object.assign({}, e);
          } else {
            return e;
          }
        });
        console.log(obj);
        new Promise(function(resolve, reject) {
          for (let i = 0; i < obj.length; i++) {
            // console.log(i);
            for (let j in obj[i]) {
              if (j == "remarks") {
                delete obj[i][j];
              }
              if (
                obj[i]["traffic"] === true ||
                obj[i]["traffic1"] === true ||
                obj[i]["traffic2"] === true ||
                obj[i]["business"] === true ||
                obj[i]["business1"] === true ||
                obj[i]["business2"] === true
              ) {
                console.warn(j);
                reject();
              } else {
                if (obj[i][j] === false) {
                  delete obj[i][j];
                }
              }
            }
          }
          resolve(obj);
        })
          .then(obj => {
            let arr = that.eachArr2(obj);
            // console.log(arr);
            return arr;
          })
          .then(
            arr => {
              let params = {
                items: arr
              };
              console.log(params);
              this.post(
                params,
                "services/app/policy/UpdateUpperPolicyCustom"
              ).then(rs => {
                if (rs.success) {
                  this.$router.push({
                    name: "policyupper4",
                    query: {
                      batchId: this.id
                    }
                  });
                } else {
                  // console.log(this.policylist);
                  console.log(rs.result.state);
                  console.log(rs.result.errorMessage);
                }
              });
            },
            err => {
              console.log("信息填写错误");
              this.$message({
                type: "warning",
                message: "信息填写错误"
              });
            }
          );
      }
    },
    //上一步
    toUp() {
      this.$router.push({
        name: "policyupper2",
        query: {
          batchId: this.id
        }
      });
    },
    //详情
    toDetail(ids) {
      this.$router.push({
        name: "policyupedit",
        query: {
          batchId: this.id,
          policyId: ids,
          status: this.status,
          stream: 1
        }
      });
    },
    //新建
    toEdit() {
      this.$router.push({
        name: "policyupnewdd",
        query: {
          batchId: this.id,
          insuranceId: this.insuranceId,
          stream: 1,
          status: this.status
        }
      });
    }
  },
  watch: {
    islimit() {
      if (this.islimit == true) {
        this.copyinfo.expiryDate = "";
      }
    }
  }
};
</script>
<style lang='scss' scoped>
.wd100 {
  width: 100px;
  height: 32px;
}
.set10 {
  margin-right: 10px;
}
.set30 {
  margin-left: 30px;
}
.app-container {
  .app-box {
    .p-detail {
      p {
        font-size: 18px;
        color: #333;
        margin: 0 0 30px 0;
        display: flex;
        justify-content: flex-start;
        align-items: center;
        i {
          color: #ee6000;
          font-size: 18px;
          margin: 3px 12px 0 0;
        }
        span {
        }
        .add {
          font-size: 10px;
          color: #fff;
          background: #ff9430;
          border-radius: 8px;
          width: 30px;
          height: 15px;
          display: inline-block;
          text-align: center;
          margin-right: 10px;
          transform: scale(0.9);
        }
        .state {
          width: 50px;
          height: 20px;
          display: flex;
          justify-content: center;
          align-items: center;
          font-size: 12px;
          border-radius: 3px;
          color: #ffffff;
        }
        .state1 {
          background: #027dca;
        }
        .state2 {
          background: #389e0d;
        }
        .state3 {
          background: #666666;
        }
        .state4 {
          background: #ff7819;
        }
        .state5 {
          background: #cf1322;
        }
        .state6 {
          background: #389e0d;
        }
      }
      .d-box {
        background: #eaf5fb;
        //width: 100%;
        min-height: 79px;
        padding: 15px 30px;
        position: relative;
        .editbatch {
          position: absolute;
          width: 78px;
          min-height: 28px;
          font-size: 13px;
          color: #027dca;
          right: 0;
          top: -52px;
          padding: 0;
          border: 0;
          outline: none;
          cursor: pointer;
          display: flex;
          justify-content: flex-end;
        }
        p {
          margin: 0;
          span {
            font-size: 12px;
            color: #95bacc;
          }
          .d-setc {
            color: #2e94c5;
          }
          .isF:first-child {
            display: none;
          }
        }
        p:nth-of-type(1) {
          margin-bottom: 8px;
        }
        .minflao{
					width:100%;
					min-height:28px;
					font-size:13px;
					color:#95bacc;
					.isF:first-child{
						display:none;
					}
					.d-setc{
						color: #2e94c5;
						margin-top:3px;
						display:block;
						float:left;
						line-height:28px;
					}
					.minflao_first{
						margin-top:3px;
						display:block;
						float:left;
						line-height:28px;
					}
					
				}
      }
    }
    .p-list {
      //width:100%;
      .util-table {
        //width:100%;
        height: 80px;
        border: 0;
        margin-top: 30px;
        //border-bottom:1px solid #e8e8e8;
        border-collapse: collapse;
        tr {
          th {
            background: #334750;
            color: #fff;
            border: 0;
            text-align: center;
          }
          td {
            //padding:10px 0;
            line-height: 40px;
            font-size: 14px;
            border-bottom: double #e8e8e8;
            .inputset {
              background: #e8e8e8;
              border: 1px solid #c3c1c1;
              width: 45px;
              height: 21px;
              text-align: right;
              color: #333333;
              font-size: 12px;
              padding: 3px;
            }
            span {
              font-size: 13px;
            }
            .setred {
              border: 1px solid #ff0000;
            }
            a {
              color: #027dca;
              font-size: 13px;
            }
            .addN {
              font-size: 14px;
              color: #027dca;
              cursor: pointer;
            }
          }
          .setc {
            text-align: center;
            font-size: 12px;
            color: #333333;
          }
          .btnsetc {
            justify-content: center;
            margin-left: 0;
            position: relative;
            a:not(:first-of-type) {
              margin-left: 12px;
            }
            .Proportionedit_delete {
              position: absolute;
              width: 250px;
              top: 100%;
              left: -130px;
              background: red;
            }
            .Proportionedit {
              position: absolute;
              width: 420px;
              height: 164px;
              top: 100%;
              right: 0;
              display: flex;
              flex-direction: column;
              justify-content: flex-start;
              z-index: 33;
              padding: 10px 0 10px 0;

              .Proportionedit_top {
                width: 100%;
                height: 93px;
                display: flex;
                margin-bottom: 20px;
                .Proportionedit_left {
                  width: 50%;
                  height: 100%;
                  display: flex;
                  justify-content: flex-start;
                  flex-direction: column;
                  align-items: center;

                  .Proportionedit_title {
                    width: 100%;
                    font-size: 14px;
                    color: #40819e;
                    margin: 0;
                    height: 22px;
                    margin-bottom: 11px;
                    text-align: center;
                  }
                  .Proportionedit_name {
                    width: 100%;
                    display: flex;
                    justify-content: space-around;
                    align-items: center;
                    height: 22px;
                    margin-bottom: 5px;
                    font-size: 13px;
                    color: #666666;
                    .Proportionedit_inp {
                      width: 50px;
                      font-size: 12px;
                      color: #333333;
                      height: 22px;
                      text-align: center;
                      outline: none;
                      border: 1px solid #dcdfe6;
                      border-radius: 4px;
                    }
                  }
                  .actives {
                    .Proportionedit_inp {
                      border: 1px solid red;
                    }
                  }
                  .activess {
                    .Proportionedit_inp {
                      border: 1px solid red;
                    }
                  }
                }
              }
              .Proportionedit_btn {
                width: 100%;
                height: 28px;
                margin-top: 27px;
                display: flex;
                justify-content: flex-end;
                align-items: center;
                button {
                  background: #f7f7f7;
                  border: 1px solid #dddddd;
                  border-radius: 5px;
                  width: 50px;
                  height: 28px;
                  margin-left: 20px;
                  cursor: pointer;
                }
                .surebtn {
                  background: #ff7819;
                  border: 1px solid #ee6000;
                  border-radius: 5px;
                  outline: none;
                  color: #ffffff;
                }
              }
            }
          }
        }
      }
    }
    .p-btn {
      text-align: center;
      margin: 20px 0;
      .setborder {
        background: #ff7819;
        border-radius: 4px;
        font-size: 14px;
        color: #ffffff;
      }
    }
  }
}
.informationaa {
  width: 100%;
  margin: 0 auto 20px;
  font-size: 12px;
  position: relative;
}
.informations {
  margin-bottom: 0;
}

.texts {
  width: 385px;
  margin-top: 10px;
  font-size: 13px;
  color: #cbcbcb;
  letter-spacing: 0;
  text-align: left;
  text-indent: 0;
  margin: 20px 0 0 0;
  line-height: 18px;
  .icon-xuanzhong {
    color: #ff7819;
    font-size: 8px;
  }
  span {
    color: #1989fa;
  }
}
.sscheckbox {
  position: absolute;
  left: 350px;
  top: 0;
  height: 100%;
  width: 80px;
}

.selects {
  width: 328px;
  position: relative;
}

.dialog-max {
  width: 100%;
  height: 200px;
  overflow-y: auto;
}
.visi-wrp {
  padding: 6px 0;
  box-sizing: border-box;
  width: 80%;
  margin: 0 auto;
  font-size: 12px;
  height: 60px;
  overflow-y: auto;
}
.dialog-sec-wp {
  text-align: center;
  padding-top: 10px;
  padding-bottom: 0;
  margin-left: -100px;
}
.dateinp {
  font-size: 12px;
  width: 150px;
}
.informationdd {
  display: flex;
  justify-content: center;
  align-items: center;
}
.btn {
  display: block;
  margin-left: -100px;
}
.util-table th:first-child,
.util-table .util-tab:first-child {
  padding: 0;
}
.havebor {
  th {
    border: 1px solid red;
  }
}

.candeletes {
  margin-bottom: 20px;
}

.btncenters {
  width: 100%;
  height: auto;
  display: flex;
  justify-content: center;
  align-items: center;
}
.btncenter {
  display: block;
  margin: 0 auto;
}
.line {
  text-align: center;
}
.app-container .app-box .p-detail .texts {
  width: 328px;
  margin-top: 10px;
  font-size: 13px;
  color: #cbcbcb;
  letter-spacing: 0;
  text-align: left;
  text-indent: 0;
  margin: 10px 0 20px 0;
  line-height: 18px;

  .icon-xuanzhong {
    color: #ff7819;
    font-size: 8px;
  }
  span {
    color: #1989fa;
  }
}
.app-container .policyupper3c .p-detail .dialog-tit {
  font-size: 14px;
}
</style>
<style type="text/css">